﻿Imports System.Data
Imports System.Data.SqlClient
Public Class modifica_clientes
    Dim namefile, TipFile1, File, RutCambio As String
    Sub Carga_informacion()
        Dim SQL As String = "select * from Representantes where Ruc='" & Ruc & "'" & " and DNI='" & dni & "'"
        Dim da As SqlDataAdapter
        Dim dt As New DataTable
        Try
            da = New SqlDataAdapter(SQL, nCnn)
            da.Fill(dt)
            TextBox1.Text = RTrim(dt.Rows(0)("Tipo"))
            TextBox2.Text = RTrim(dt.Rows(0)("DNI"))
            TextBox3.Text = RTrim(dt.Rows(0)("Nombres"))
            TextBox4.Text = RTrim(dt.Rows(0)("Participacion"))
            TextBox5.Text = RTrim(dt.Rows(0)("DNIConyuge"))
            TextBox6.Text = RTrim(dt.Rows(0)("NombreConyuge"))
            TextBox7.Text = RTrim(dt.Rows(0)("Direccion"))
            Dim ruta As String = "\\pelimaplic01\sec\" & RTrim(dt.Rows(0)("Archivo"))
        Catch ex As Exception
            MsgBox("Error buscando rep: " & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Sub Cambia_Archivos()
        Dim Origen As String = Label8.Text
        Dim NewNameJpg As String = Label1.Text & "_" & TextBox2.Text & ".jpg"
        Dim NewNamePdf As String = Label1.Text & "_" & TextBox2.Text & ".pdf"
        Dim NewNameZip As String = Label1.Text & "_" & TextBox2.Text & ".zip"
        Dim NewNameRar As String = Label1.Text & "_" & TextBox2.Text & ".rar"
        Select Case TipFile1
            Case Is = "jpg"
                Dim Destino As String = "\\pelimaplic01\sec\" & NewNameJpg
                My.Computer.FileSystem.CopyFile(Origen, Destino, True)
                RutCambio = Destino
            Case Is = "JPG"
                Dim Destino As String = "\\pelimaplic01\sec\" & NewNameJpg
                My.Computer.FileSystem.CopyFile(Origen, Destino, True)
                RutCambio = Destino
            Case Is = "pdf"
                Dim Destino As String = "\\pelimaplic01\sec\" & NewNamePdf
                My.Computer.FileSystem.CopyFile(Origen, Destino, True)
                RutCambio = Destino
            Case Is = "PDF"
                Dim Destino As String = "\\pelimaplic01\sec\" & NewNamePdf
                My.Computer.FileSystem.CopyFile(Origen, Destino, True)
                RutCambio = Destino
            Case Is = "zip"
                Dim Destino As String = "\\pelimaplic01\sec\" & NewNameZip
                My.Computer.FileSystem.CopyFile(Origen, Destino, True)
                RutCambio = Destino
            Case Is = "ZIP"
                Dim Destino As String = "\\pelimaplic01\sec\" & NewNameZip
                My.Computer.FileSystem.CopyFile(Origen, Destino, True)
                RutCambio = Destino
            Case Is = "rar"
                Dim Destino As String = "\\pelimaplic01\sec\" & NewNameRar
                My.Computer.FileSystem.CopyFile(Origen, Destino, True)
                RutCambio = Destino
            Case Is = "RAR"
                Dim Destino As String = "\\pelimaplic01\sec\" & NewNameRar
                My.Computer.FileSystem.CopyFile(Origen, Destino, True)
                RutCambio = Destino
        End Select
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
       
    End Sub

    Private Sub modifica_clientes_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Len(dni) <> 0 Then
            Call Carga_informacion()
        Else
            TextBox1.Focus()
        End If
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        OpenFileDialog1.Title = "Abrir archivo de orden de compra de clientes..."
        OpenFileDialog1.Filter = "Archivos PDF|*.pdf|Archivos JPG|*.jpg|Archivos ZIP|*.zip|Archivos RAR|*.rar"
        OpenFileDialog1.ShowDialog()
        If Len(OpenFileDialog1.FileName) <> 0 Then
            NameFile = Me.OpenFileDialog1.FileName.Substring(Me.OpenFileDialog1.FileName.LastIndexOf("\") + 1, Me.OpenFileDialog1.FileName.Length - Me.OpenFileDialog1.FileName.LastIndexOf("\") - 1)
            Dim Tip1 = Len(OpenFileDialog1.FileName) - 2
            TipFile1 = Mid(OpenFileDialog1.FileName, Tip1, Len(OpenFileDialog1.FileName))
            File = Mid(OpenFileDialog1.FileName, Tip1, Len(OpenFileDialog1.FileName))
            TextBox8.Text = OpenFileDialog1.FileName
        End If
    End Sub

    Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
        If Asc(e.KeyChar) = 13 Then
            TextBox2.Focus()
        End If
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.Uppercase)
        TextBox1.SelectionStart = Len(TextBox1.Text)
    End Sub

    Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
        Select Case Asc(e.KeyChar)
            Case 47 To 58
            Case 8
            Case 13
                TextBox3.Focus()
            Case Else
                e.Handled = True
        End Select
    End Sub

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged

    End Sub
End Class